package org.newlucene.suggest;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.newlucene.core.analysis.Analyzer;
import org.newlucene.core.analysis.Token;

public class GramAnalyzer implements Analyzer
{
   private String regexp = "[a-z0-9_]+";
   private Pattern pattern = Pattern.compile(regexp);
   private Matcher matcher = pattern.matcher("");

   public void set(String text)
   {
      this.matcher.reset(text);
   }

   public Token next()
   {
      if (matcher.find())
      {
         String text = matcher.group();
         return new Token(text);
      }
      else
      {
         return null;
      }
   }
   
   public static void main(String[] args)
   {
	   GramAnalyzer gramAnalyzer = new GramAnalyzer();
	   gramAnalyzer.set("gram_cr gram_ra gram_af gram_ft");
	   Token t;
	   while((t = gramAnalyzer.next()) != null)
	   {
		   System.out.println(t);
	   }
   }
}